package com.tanker.common;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * @author xqxue
 * @time 2017年9月18日 下午2:38:45
 */
public class InitListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent context) {
		// TODO Auto-generated method stub

	}

	@Override
	public void contextInitialized(ServletContextEvent context) {
		initConfig(context);
		ServletContext sc = context.getServletContext();
		
		// 取得系统常量
		WebApplicationContext wac = WebApplicationContextUtils .getWebApplicationContext(sc);

	}
	
	private void initConfig(ServletContextEvent context) {

		ServletContext sc = context.getServletContext();
		WebApplicationContext applicationContext = WebApplicationContextUtils
				.getWebApplicationContext(sc);

		ConfigData configData = (ConfigData) applicationContext
				.getBean("configData");
		Constants.configData = configData;
		sc.setAttribute(Constants.SYSTEM_CONFIG, configData);
	}

}
